﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using DataContextLayer;

namespace BlueHarvestSnippetGenerator.Pages
{
	/// <summary>
	/// Interaction logic for TutorialChoice.xaml
	/// </summary>
	public partial class TutorialChoice : Page
	{

        private enum Languages
        {
            
            Csharp = 0,
            Java
        };

       
        private string _directoryPath;

		public TutorialChoice()
		{
		    InitializeComponent();
		}

        private void LanguageListSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            switch (LanguageList.SelectedIndex)
            {
                case (int)Languages.Csharp:
                    _directoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                            @"My BlueHarvest\Tutorials\Csharp\");
                    GetTutorialsAvailable(_directoryPath);
                    break;
                case (int)Languages.Java:
                    _directoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                                            @"My BlueHarvest\Tutorials\Java\");
                    GetTutorialsAvailable(_directoryPath);
                    break;
            }
        }

        private void GetTutorialsAvailable(string directoryPath)
        {
            AvailableView();

            var tutorialList = new List<string>(Directory.GetFiles(_directoryPath));

            TutList.ItemsSource = tutorialList.Select(Path.GetFileNameWithoutExtension).ToList();
        }

        
        private void AvailableView()
        {
            lblTutorialsAvailable.Visibility = Visibility.Visible;
            TutList.Visibility = Visibility.Visible;
        }


        private void BtnSubmitChoiceClick(object sender, RoutedEventArgs e)
        {
            if (TutList.SelectedItem != null)
            {
                UserProfile.CurrentTutorial = string.Format("{0}{1}.xml", _directoryPath, TutList.SelectedItem);
                NavigationService.PageNav(PageName.TutorialPage);
            }
            else
            {
                MessageBox.Show("Pick a Tutorial");
            }
        }

       


	}
}
